package com.naicha.wechat.wechat.factory;

import com.naicha.wechat.wechat.enums.WeChatMessageType;
import com.naicha.wechat.wechat.factory.impl.ImageMessageImpl;
import com.naicha.wechat.wechat.factory.impl.TestMessageImpl;
import com.naicha.wechat.wechat.factory.model.WeChatMessageBase;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * @author NaiCha
 * @date 2019/5/6 9:59
 * @description 发送消息动态工厂
 **/
@Slf4j
public class DynamicMessageFactory {


    public static Object getMessageContent(String openID,String type,Map<String,Object> data){
        DynamicMessageBean messageBean = getMessageBean(type);
        return messageBean.getMessageObject(openID, type, data);
    }


    /**
     * 动态获取消息bean
     * @param type
     * @return
     */
    private static DynamicMessageBean getMessageBean(String type){
        if (type.equals(WeChatMessageType.TEXT.getDisplay())){
            return new TestMessageImpl();
        }else if(type.equals(WeChatMessageType.IMAGE.getDisplay())){
            return new ImageMessageImpl();
        }else {
            //暂无当前对应消息类型
            return new DynamicMessageBean() {
                @Override
                public WeChatMessageBase getMessageObject(String openID, String type, Map<String, Object> data) {
                    log.error("暂无当前对应消息类型:" + type);
                    return new WeChatMessageBase(openID,type);
                }
            };
        }
    }

}
